﻿
$(document).ready(function (e) {
    
    var date = new Date().getFullYear();
    $("#copyright").text("Copyright© " + 2024 +"-" + date + " AVCC. All Rights Reserved. 艾威康 版权所有");
    $("#loginmsg").css("display", "none");
    var formInit = function () {
        var width = $(window).width();
        var height = $(window).height();
        var x = width - $("#login-form").width() - 100;
        var y = (height - $("#login-form").height()) / 2;
        $("#login-form").css({ "margin-left": x + "px", "margin-top": y + "px" });
    }

    formInit();

    $(window).bind({
        resize: function () {
            formInit();
        }
    });
    $('.form-control').on('keyup', function (e) {
        var name = $('#uid').val()
        var pwd = $('#pwd').val()
        if (e.keyCode == 13 && name != '' && pwd != '') {
            loginBtn()
        }
    })
});


//$("#login-btn").bind({
//    click: function () {
//        var uid = $("#uid").val();
//        debugger
//        var pwd = $("#pwd").val();
//        $.ajax({
//            type: "POST",
//            url: "../api/Data/Login",
//            data: JSON.stringify({ "uid": uid, "pwd": pwd }),
//            contentType: "application/json",
//            success: function (data) {
//                if (data.code == 1) {
//                    $("#loginmsg").css("display", "none");
//                    window.location.href = "/Home/Index";
//                } else {
//                    $("#loginmsg").css("display", "block");
//                }
//            }
//        });
//    }
//});
var loginBtn = function () {
    var uid = $("#uid").val();
    var pwd = $("#pwd").val();
    //if (uid != "admin" || pwd != "admin") {
    //    $("#loginmsg").css("display", "block");
    //    return;
    //}
    $.ajax({
        type: "POST",
        url: "/api/User/Login",
        data: JSON.stringify({ "uid": uid, "pwd": pwd }),
        contentType: "application/json",
        success: function (data) {
            if (data.code == 1) {
                $("#loginmsg").css("display", "none");
                window.location.href = "/index.html";
                localStorage.setItem("username", data.name);
            } else {
                $("#loginmsg").css("display", "block");
            }
        }
    });
}
function loginfoward()
{
    if (localStorage.getItem("username")) {
        window.open("/index.html","index");
    } else {
        window.open("/login.html","index");
    }
}
function loginout() {
    $.ajax({
        type: "GET",
        url: "/api/User/ClearLoginCache",
        contentType: "application/json",
        success: function (data) {
            window.location.href = "/login.html"
        }
    });
    localStorage.removeItem("username");
}
